<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let users = [
            ["123", "123", 1000],
            ["admin", "123", 100],
        ];
        let loginUser = null;
        let money = 0;

        login();

        // 登录
        function login() {
            const account = prompt("请输入账号")
            const password = prompt("请输入密码")

            for (let i = 0; i < users.length; i++) {
                if (account == users[i][0] && password == users[i][1]) {
                    console.log("登录成功", users[i]);
                    // loginUser = users[i];
                    money = users[i][2];
                    atm();
                }
            }
            // 对 null 进行取反后，为 true
            if (!loginUser) {
                console.log("登录失败");
            }
        }

        // 存款操作
        function save() {
            const saveMoney = prompt('请输入存款金额：') - 0;
            loginUser[2] += saveMoney;
            console.log(`存款金额为:${saveMoney}, 账户余额为:${loginUser[2]}`);
            const isContinue = prompt('是否继续存款：(y/n)');
            if (isContinue === 'y') {
                save();
            }
        }

        // atm操作流程
        function atm() {
            const option = prompt("请选择业务: 1.查询 2.存款 3.取款 4.退出");
            switch (option) {
                case "1":
                    console.log(`账户余额为: ${loginUser[2]}`);
                    atm();
                    break;
                case "2":
                    save();
                    atm();
                    break; // 结束switch
                case "3":
                    atm();
                    break;
                case "4":
                    // 结束switch
                    break;
            }
        }
    </script>
</body>

</html>